package com.xh.jf_blog.common.util;

import lombok.Data;

import java.util.List;

/**
 * @Author PangJunjie
 * @Date 2024/1/12/012
 */
@Data
public class R {
    private Integer code = 200;
    private String msg = "success";
    private Object data;
    private Long count;

    public static R ok() {
        return new R();
    }

    public static R ok(Object data) {
        R r = new R();
        r.setData(data);
        return r;
    }

    public static R ok(String msg) {
        R r = new R();
        r.setMsg(msg);
        return r;
    }

    public static R error(Integer code, String msg) {
        R r = new R();
        r.setCode(code);
        r.setMsg(msg);
        return r;
    }

    public static R error(Integer code) {
        return error(code, "error");
    }

    public static R error(String msg) {
        return error(500, msg);
    }

    public static R error() {
        return error(500, "error");
    }

    public static R result(int result) {
        return result > 0 ? ok() : error();
    }

    public static R page(long total, List<?> list) {
        R r = new R();
        r.setMsg("暂无数据");
        r.setCode(0);
        r.setCount(total);
        r.setData(list);
        return r;
    }

    public static R edit(String data) {
        R r = new R();
        r.setCode(0);
        r.setData(data);
        return r;
    }
}
